
var BaseData = {
    
    init:function(){
        gameScore = BaseData.getGameScore(Config.gameScoreKey);
        Config.downUrl += Config.version + "/";
    },

    saveGameScore:function(_score){
        Laya.LocalStorage.setItem(Config.gameScoreKey,_score);
    },

    getGameScore:function(_key){
        var score = Laya.LocalStorage.getItem(_key);
        if(score == null || score == undefined || score == ""){
           score = 0;
        }
        return score;
    },

    saveUserData:function(_key,_data){
        Laya.LocalStorage.setItem(Config.gameScoreKey + _key,_data);
    },

    getUserData:function(_key){
        var _data = Laya.LocalStorage.getItem(Config.gameScoreKey + _key);
        if(_data == null || _data == undefined || _data == ""){
            _data = 0;
        }
        return _data;
    },

    GameData : null,
    saveGameData:function(data){
        BaseData.GameData  = data
    },
    getGameData:function(_key){
        return BaseData.GameData
    },
    initSceneGameData:function (sceneObj) {
        if(Config.channelID == 1){
            if(BaseData.GameData && sceneObj){
                if(sceneObj.recommend_list && BaseData.GameData.list){
                    for (var i = 0; i < BaseData.GameData.list.length; i++) {
                            var _game = BaseData.GameData.list[i];
                            // var _recommendItem = new recommend_itemUI();
                            var _recommendItem = sceneObj.recommend_list["item_"+(i+1)]
                            _recommendItem.title.text = _game.name;
                            _recommendItem.img.skin = _game.img;
                            _recommendItem.visible = true;
                            _recommendItem.on(Laya.Event.MOUSE_DOWN, BaseData, BaseData.goOtherGame,[_game.appID,_game.path,_game.extra_data]);
                    }
                    sceneObj.recommend_list.visible = true;
                    sceneObj.recommend_game_show = false;
                    sceneObj.recommend_list.btnShow.on(Laya.Event.MOUSE_DOWN, BaseData, BaseData.showOrHideGameList,[sceneObj]);
                }
                if(sceneObj.recommend_l && BaseData.GameData.left){
                    for (var i = 0; i < BaseData.GameData.left.length; i++) {
                            var _game = BaseData.GameData.left[i];
                            // var _recommendItem = new recommend_itemUI();
                            var _recommendItem = sceneObj.recommend_l["item_"+(i+1)]
                            _recommendItem.title.text = _game.name;
                            _recommendItem.img.skin = _game.img;
                            _recommendItem.visible = true;
                            _recommendItem.on(Laya.Event.MOUSE_DOWN, BaseData, BaseData.goOtherGame,[_game.appID,_game.path,_game.extra_data]);
                    }
                    sceneObj.recommend_l.visible = true;
                }
                if(sceneObj.recommend_r && BaseData.GameData.right){
                    for (var i = 0; i < BaseData.GameData.right.length; i++) {
                            var _game = BaseData.GameData.right[i];
                            // var _recommendItem = new recommend_itemUI();
                            var _recommendItem = sceneObj.recommend_r["item_"+(i+1)]
                            _recommendItem.title.text = _game.name;
                            _recommendItem.img.skin = _game.img;
                            _recommendItem.visible = true;
                            _recommendItem.on(Laya.Event.MOUSE_DOWN, BaseData, BaseData.goOtherGame,[_game.appID,_game.path,_game.extra_data]);
                    }
                    sceneObj.recommend_r.visible = true;
                }
            }
        }
        
    },
    goOtherGame : function(appId,path,extraData){
        //跳转到小程序
        extraData.name = Config.game
        if(Config.channelID == 1){
            wx.navigateToMiniProgram({
                appId:appId,
                path:path,
                extraData:extraData
            });
        }
    },
    showOrHideGameList : function(sceneObj){
        //显示或者隐藏推荐游戏列表
        if(!sceneObj.recommend_game_show ){
            Laya.Tween.to(sceneObj.recommend_list,{x:0},600);
            sceneObj.recommend_game_show = true;
        }else{
            Laya.Tween.to(sceneObj.recommend_list,{x:-402},600);
            sceneObj.recommend_game_show = false;
        }
        
    },
    //清理所有无用UI
    clearUI:function(){

         Laya.loader.clearTextureRes("ui/title.png");
         Laya.loader.clearTextureRes("ui/bg.jpg");
         Laya.loader.clearTextureRes("res/atlas/rank.atlas");
         Laya.loader.clearTextureRes("res/atlas/result.atlas");
         Laya.loader.clearTextureRes("res/atlas/ui.atlas");
    },

};
